package rsparql.test;

import static org.junit.Assert.*;

import java.io.IOException;

import org.junit.Test;

import rsparql.SparqlQuery;

public class SparqlQueryTestCase {

	@Test
	public void testLocalFile() throws IOException {
		String query = "SELECT ?x ?name WHERE {?x  <http://www.w3.org/2001/vcard-rdf/3.0#FN>  ?name}";

		SparqlQuery sparqlQuery = new SparqlQuery();

		sparqlQuery.execute(query, "queries/vc-db-1.rdf");
		
		SparqlPrinter.print(sparqlQuery);

		assertEquals(2, sparqlQuery.cols());
		assertEquals(4, sparqlQuery.rows());

		sparqlQuery.clear();
	}

	@Test
	public void testRemoteEndPoint() throws IOException {
		String query = "SELECT ?date ?number ?season WHERE { "
				+ "?e <http://dbpedia.org/ontology/series>         <http://dbpedia.org/resource/The_Sopranos>  . "
				+ "?e <http://dbpedia.org/ontology/releaseDate>    ?date                                       . "
				+ "?e <http://dbpedia.org/ontology/episodeNumber>  ?number                                     . "
				+ "?e <http://dbpedia.org/ontology/seasonNumber>   ?season "
				+ "} LIMIT 10";

		SparqlQuery sparqlQuery = new SparqlQuery();

		sparqlQuery.execute(query,
				"http://dbpedia.org/sparql");

		SparqlPrinter.print(sparqlQuery);

		assertEquals(3, sparqlQuery.cols());
		assertEquals(10, sparqlQuery.rows());

		sparqlQuery.clear();
	}

	@Test
	public void testLocalQueryFileEndPoint() throws IOException {
		SparqlQuery sparqlQuery = new SparqlQuery();

		sparqlQuery.execute("queries/query.rq",
				"http://dbpedia.org/sparql");

		SparqlPrinter.print(sparqlQuery);

		assertEquals(3, sparqlQuery.cols());
		assertEquals(10, sparqlQuery.rows());

		sparqlQuery.clear();
	}
	
	@Test
	public void testGeoEndPoint() throws IOException {
		SparqlQuery sparqlQuery = new SparqlQuery();

		sparqlQuery.execute("queries/new-york.rq",
				"http://dbpedia.org/sparql");

		SparqlPrinter.print(sparqlQuery);

		//assertEquals(3, sparqlQuery.cols());
		//assertEquals(10, sparqlQuery.rows());

		sparqlQuery.clear();
	}
}
